package Behaviour;

import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;

import javax.swing.JPanel;

import map.Map;
import View.PanelGui;

public class CarPass extends CyclicBehaviour {

	private static final long serialVersionUID = 1L;
	private Map map;
	private int STEP = 0;
	private JPanel panel;
	private PanelGui panelGui;

	public CarPass(Agent a, long period, Map map, PanelGui jPanel) {
		super(a);
		this.map = map;
		this.panel = jPanel.getDrawPanel();
		this.panelGui = jPanel;
	}

	@Override
	public void action() {
		STEP++;
		switch (STEP % 8) {
		case 0:
			this.myAgent.addBehaviour(new AddCar(map, panelGui, STEP));
			break;
		case 1:
			this.myAgent.addBehaviour(new SetCrossRoads(myAgent, map, panel));
			break;
		case 2:
			this.myAgent.addBehaviour(new MoveCars(map, panel));
			break;
		case 3:
			this.myAgent.addBehaviour(new DeleteArrivedCars(map));
			break;
		case 4:
			this.myAgent.addBehaviour(new ManageWaitList(map));
			break;
		case 5:
			this.myAgent.addBehaviour(new UpdateWeightedEdge(map));
			break;
		case 6:
			this.myAgent.addBehaviour(new ChangeCroassRoads(myAgent, map));
			break;
		case 7:
			this.myAgent.addBehaviour(new UpdatePerformanceMeasure(myAgent, map, panelGui));
		}

		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	};

}
